package com.warmheart.base.service;

import java.util.List;
import java.util.Map;
import java.util.function.Function;

import com.warmheart.base.entity.BaseEntity;
import com.warmheart.base.page.PageInfo;
import com.warmheart.core.rs.model.GroupByCntResultModel;

/**
 * 
 * @ClassName: IBaseService
 * @Description: SERVICE基本接口
 * @author ZhangJianyang
 * @date 2025-06-16 09:37:02
 *
 * @param <T>
 */
public interface IBaseService<T extends BaseEntity<?, ?>> {

    /**
     * 
     * @Title: queryById
     * @Description: 根据主键查询单条记录
     * @author ZhangJianyang
     * @param id
     * @return
     */
    public T queryById(Integer id);
    
    /**
     * 
     * @Title: queryByIds
     * @Description: 根据ID列表批量查询数据列表
     * @author ZhangJianyang
     * @param ids
     * @return
     */
    public List<T> queryByIds(Integer[] ids);

    /**
     * 
     * @Title: queryByIdList
     * @Description: 根据ID列表批量查询数据列表
     * @author ZhangJianyang
     * @param idList
     * @return
     */
    public List<T> queryByIdList(List<Integer> idList);
    
    /**
     * 
     * @Title: selectInfoMapByIds
     * @Description: 根据ID列表批量查询数据信息
     * @author ZhangJianyang
     * @param ids
     * @return
     */
    public Map<Integer, T> selectInfoMapByIds(Integer[] ids);

    /**
     * 
     * @Title: selectInfoMapByIdList
     * @Description: 根据ID列表批量查询数据信息
     * @author ZhangJianyang
     * @param idList
     * @return
     */
    public Map<Integer, T> selectInfoMapByIdList(List<Integer> idList);

    /**
     * 
     * @Title: selectOne
     * @Description: 通用查询单条记录
     * @author ZhangJianyang
     * @param entity
     * @return
     */
    public T selectOne(T entity);
    
    /**
     * 
     * @Title: selectOnlyOne
     * @Description: 通用查询最多只查询一条记录
     * @author ZhangJianyang
     * @param entity
     * @return
     */
    public T selectOnlyOne(T entity);
    
    /**
     * 
     * @Title: selectCombineOne
     * @Description: 通用联合查询单条记录
     * @author ZhangJianyang
     * @param entity
     * @return
     */
    public Map<String, Object> selectCombineOne(T entity);

    /**
     * 
     * @Title: selectList
     * @Description: 通用查询列表
     * @author ZhangJianyang
     * @param entity
     * @return
     */
    public List<T> selectList(T entity);
    
    /**
     * 
     * @Title: selectCombineList
     * @Description: 通用联合查询列表
     * @author ZhangJianyang
     * @param entity
     * @return
     */
    public List<Map<String, Object>> selectCombineList(T entity);

    /**
     * 
     * @Title: selectInfoMap
     * @Description: 通用字段对象映射查询
     * @author ZhangJianyang
     * @param entity
     * @return
     */
    public <F> Map<F, T> selectInfoMap(T entity, Function<T, F> function);

    /**
     * 
     * @Title: selectListMap
     * @Description: 通用字段对象列表映射查询
     * @author ZhangJianyang
     * @param entity
     * @param function
     * @return
     */
    public <F> Map<F, List<T>> selectListMap(T entity, Function<T, F> function);

    /**
     * 
     * @Title: queryByCount
     * @Description: 通用查询列表数量
     * @author ZhangJianyang
     * @param entity
     * @return
     */
    public int queryByCount(T entity);
    
    /**
     * 
     * @Title: queryCombineCount
     * @Description: 通用联合查询列表数量
     * @author ZhangJianyang
     * @param entity
     * @return
     */
    public int queryCombineCount(T entity);

    /**
     * 
     * @Title: queryByList
     * @Description: 通用分页查询
     * @author ZhangJianyang
     * @param entity
     * @return
     */
    public PageInfo<T> queryByList(T entity);
    
    /**
     * 
     * @Title: queryCombineList
     * @Description: 通用分页联合查询
     * @author ZhangJianyang
     * @param entity
     * @return
     */
    public PageInfo<Map<String, Object>> queryCombineList(T entity);

    /**
     * 
     * @Title: selectSingleList
     * @Description: 查询单个字段列表
     * @author ZhangJianyang
     * @param entity
     * @param distinctFlags
     * @return
     */
    public <F> List<F> selectSingleList(T entity, Boolean... distinctFlags);

    /**
     * 
     * @Title: selectMultipleList
     * @Description: 查询多个字段列表
     * @author ZhangJianyang
     * @param entity
     * @param distinctFlags
     * @return
     */
    public List<Map<String, Object>> selectMultipleList(T entity, Boolean... distinctFlags);

    /**
     * 
     * @Title: selectKeyValueList
     * @Description: 查询KEY以及VALUE映射列表
     * @author ZhangJianyang
     * @param entity
     * @param distinctFlags
     * @return
     */
    public List<Map<String, Object>> selectKeyValueList(T entity, Boolean... distinctFlags);

    /**
     * 
     * @Title: selectGroupByCntList
     * @Description: 指定字段分组查询数量
     * @author ZhangJianyang
     * @param entity
     * @param distinctFlags
     * @return
     */
    public <F> List<GroupByCntResultModel<F>> selectGroupByCntList(T entity, Boolean... distinctFlags);

    /**
     * 
     * @Title: selectGroupByCntInfoMap
     * @Description: 查询指定字段分组数量映射信息
     * @author ZhangJianyang
     * @param entity
     * @param distinctFlags
     * @return
     */
    public <F> Map<F, Integer> selectGroupByCntInfoMap(T entity, Boolean... distinctFlags);

    /**
     * 
     * @Title: add
     * @Description: 添加记录
     * @author ZhangJianyang
     * @param t
     * @throws Exception
     */
    public void add(T t) throws Exception;

    /**
     * 
     * @Title: update
     * @Description: 更新记录（只要不为null都进行修改，避免0被识别为空字符串）
     * @author ZhangJianyang
     * @param t
     * @throws Exception
     */
    public void update(T t) throws Exception;

    /**
     * 
     * @Title: updateBySelective
     * @Description: 更新记录（只修改只不为空的字段，也就是说null或者空字符串均被忽略）
     * @author ZhangJianyang
     * @param t
     * @throws Exception
     */
    public void updateBySelective(T t) throws Exception;

    /**
     * 
     * @Title: updateIncludeAll
     * @Description: 
     *               更新记录（对所有字段进行修改，无论是null还是空字符串，注意使用此方法，强烈建议先查询完整数据再进行修改，避免数据丢失
     *               ）
     * @author ZhangJianyang
     * @param t
     * @throws Exception
     */
    public void updateIncludeAll(T t) throws Exception;

    /**
     * 
     * @Title: deleteById
     * @Description: 根据主键删除记录
     * @author ZhangJianyang
     * @param id
     * @throws Exception
     */
    public void deleteById(Integer id) throws Exception;

    /**
     * 
     * @Title: deleteByIds
     * @Description: 根据主键数组批量删除记录
     * @author ZhangJianyang
     * @param ids
     * @throws Exception
     */
    public void deleteByIds(Integer[] ids) throws Exception;

    /**
     * 
     * @Title: deleteByIdList
     * @Description: 根据主键列表批量删除记录
     * @author ZhangJianyang
     * @param idList
     * @throws Exception
     */
    public void deleteByIdList(List<Integer> idList) throws Exception;

    /**
     * 
     * @Title: deleteBySelective
     * @Description: 根据属性条件删除记录
     * @author ZhangJianyang
     * @param entity
     * @throws Exception
     */
    public void deleteBySelective(T entity) throws Exception;

    /**
     * 
     * @Title: deleteLogicById
     * @Description: 根据主键逻辑删除记录
     * @author ZhangJianyang
     * @param id
     * @throws Exception
     */
    public void deleteLogicById(Integer id) throws Exception;

    /**
     * 
     * @Title: deleteLogicByIds
     * @Description: 根据主键数组批量逻辑删除记录
     * @author ZhangJianyang
     * @param ids
     * @throws Exception
     */
    public void deleteLogicByIds(Integer[] ids) throws Exception;

    /**
     * 
     * @Title: deleteLogicByIdList
     * @Description: 根据主键列表批量逻辑删除记录
     * @author ZhangJianyang
     * @param idList
     * @throws Exception
     */
    public void deleteLogicByIdList(List<Integer> idList) throws Exception;

    /**
     * 
     * @Title: deleteLogicBySelective
     * @Description: 根据属性条件逻辑删除记录
     * @author ZhangJianyang
     * @param entity
     * @throws Exception
     */
    public void deleteLogicBySelective(T entity) throws Exception;
}
